package com.longer.playhelper.view.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;

import com.longer.playhelper.R;
import com.longer.playhelper.presenter.SendBug_ActivityPresenter;
import com.longer.playhelper.utlis.Toast;
import com.longer.playhelper.view.iview.ISendBug_ActivityView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SendBug_Activity extends AppCompatActivity implements ISendBug_ActivityView{

    public Context context;
    @Bind(R.id.edt_sendbug_content)
    EditText edtSendbugContent;
    @Bind(R.id.edt_sendbug_tel)
    EditText edtSendbugTel;
    ProgressDialog progressDialog;

    private SendBug_ActivityPresenter presenter = new SendBug_ActivityPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sendbug);
        ButterKnife.bind(this);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("意见反馈");
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
        inti();
    }

    public void inti() {
        context = SendBug_Activity.this;

        progressDialog = new ProgressDialog(context);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("正在提交...");
    }


    @OnClick(R.id.btn_sendbug)
    public void onViewClicked() {
        if(getContent().isEmpty()){
            Toast.show("不能为空");
            return;
        }
        if(getContent().length() < 10){
            Toast.show("问题描述太短了哦~");
            return;
        }
        presenter.save();
    }

    @Override
    public String getContent() {
        return edtSendbugContent.getText().toString().trim();
    }

    @Override
    public String getTel() {
        return edtSendbugTel.getText().toString().trim();
    }

    @Override
    public void showSending() {
        progressDialog.show();
    }

    @Override
    public void hideSending() {
        if(progressDialog.isShowing()){
            progressDialog.dismiss();
        }
    }

    @Override
    public void sendFailed(String error) {
        Toast.show("提交失败！");
    }

    @Override
    public void sendSuccess() {
        Toast.show("提交成功！");
    }

    @Override
    public void toMain_Activity() {
        finish();
    }

}
